﻿Public Class TableComponent
    Implements iopt.solvency.pillarone.core.IComponent


    Public Sub Execute(ComputeContext As IComputeContext, DataContext As IDataContext) Implements IComponent.Execute

    End Sub

    Protected Overridable Sub Execute(ModelPoint As IModelPoint, ResultRow As IRow)

    End Sub


End Class





Public Class MortaliteMilieuMoisComponent
    Implements iopt.solvency.pillarone.core.IComponent

    Public Property Age As IInputArgument(Of Double)
    Public Property TauxMortaliteAnnuel As IInputArgument(Of Double(,))
    Public Property SelectionMedicale As IInputArgument(Of Double())

    Public Property Result As IOutputArgument(Of Double)

    Public Property PresenceSelectionMedicale As Boolean

    Public Sub Execute(ComputeContext As IComputeContext, DataContext As IDataContext) Implements IComponent.Execute
        If ComputeContext.Status = ComputeStatus.Period Then
            Me.Result.Set( _
                MortaliteMilieuMoisComponent.MortaliteMilieuMois( _
                    Me.Age.Get(), _
                    Me.TauxMortaliteAnnuel.Get(), _
                    Me.SelectionMedicale.Get(), _
                    ComputeContext.IterationIndex, _
                    Me.PresenceSelectionMedicale))
        End If
    End Sub

    Private Shared Function MortaliteMilieuMois(ByVal Age As Double, _
                                       ByVal txMortAn As Double(,), _
                                       ByVal sel_medicale As Double(), _
                                       ByVal NumPeriode As Integer, _
                                       ByVal presence_sel_medic As Boolean) As Double

        Dim coefBorneMin As Double = 1 - (Age - Int(Age))
        Dim coefBorneMax As Double = 1 - coefBorneMin
        Dim TxMortAge As Double = coefBorneMin * txMortAn(Age, 1) + coefBorneMax * txMortAn(Age + 1, 1)
        Dim Abt_SelMed As Double

        If presence_sel_medic Then

            Dim coef_borneMinSelMed As Double = 1 - (NumPeriode / 12 - (Int(NumPeriode / 12)))
            Dim coef_borneMaxSelMed As Double = 1 - coef_borneMinSelMed
            Dim selMed_borneMin, selMed_borneMax

            If Int(NumPeriode / 12) > sel_medicale.Count - 1 Then
                selMed_borneMin = 0
            Else
                selMed_borneMin = sel_medicale(Int(NumPeriode / 12))
            End If

            If Int(NumPeriode / 12) + 1 > sel_medicale.Count - 1 Then
                selMed_borneMax = 0
            Else
                selMed_borneMax = sel_medicale(Int(NumPeriode / 12) + 1)
            End If

            Abt_SelMed = coef_borneMinSelMed * selMed_borneMin + coef_borneMaxSelMed * selMed_borneMax

        End If

        Return TxMortAge * (1 - Abt_SelMed)
    End Function
End Class
